package electricity.controller;


import electricity.domain.DeviceInfo;
import electricity.domain.SysRegion;
import electricity.result.Result;
import electricity.service.RegionMetricService;
import electricity.vo.RegionMetricVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.swing.plaf.synth.Region;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/region")
@Tag(name = "区域指标接口")
public class RegionMetricController {

    @Resource
    private RegionMetricService regionMetricService;

    // 获取区域列表
    @GetMapping("/list")
    @Operation(summary = "区域列表")
    public Result<List<SysRegion>> getRegions() {
        List<SysRegion> regions =regionMetricService.getRegionList();
        return Result.success(regions);
    }

    // 获取指定区域的指标
    @GetMapping("/metrics")
    @Operation(summary = "区域指标")
    public Result<RegionMetricVO> getMetrics(String region) {
        RegionMetricVO metrics = regionMetricService.getMetricByRegion(region);
        return Result.success(metrics);
    }

    // 获取设备列表（用于统计）
    @GetMapping("/devices")
    @Operation(summary = "设备列表")
    public Map<String, Object> getDevices(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        List<DeviceInfo> devices = regionMetricService.getDeviceList(page, size);
        int total = regionMetricService.getDeviceTotalCount();

        Map<String, Object> result = new HashMap<>();
        result.put("records", devices);
        result.put("total", total);
        return result;
    }
}
